Add integration tests for Scenario imports

Dominik Sander 7 years ago
parent
commit
5b5da87c3a
1 changed files with 46 additions and 0 deletions
  1. 46 0
      spec/features/scenario_import_spec.rb

+ 46 - 0
spec/features/scenario_import_spec.rb

@@ -0,0 +1,46 @@
1
+require 'rails_helper'
2
+
3
+describe ScenarioImportsController do
4
+  let(:user) { users(:bob) }
5
+
6
+  before do
7
+    login_as(user)
8
+  end
9
+
10
+  it 'renders the import form' do
11
+    visit new_scenario_imports_path
12
+    expect(page).to have_text('Import a Public Scenario')
13
+  end
14
+
15
+  it 'requires a URL or file uplaod' do
16
+    visit new_scenario_imports_path
17
+    click_on 'Start Import'
18
+    expect(page).to have_text('Please provide either a Scenario JSON File or a Public Scenario URL.')
19
+  end
20
+
21
+  it 'imports a scenario that does not exist yet' do
22
+    visit new_scenario_imports_path
23
+    attach_file('Option 2: Upload a Scenario JSON File', File.join(Rails.root, 'data/default_scenario.json'))
24
+    click_on 'Start Import'
25
+    expect(page).to have_text('This scenario has a few agents to get you started. Feel free to change them or delete them as you see fit!')
26
+    expect(page).not_to have_text('This Scenario already exists in your system.')
27
+    check('I confirm that I want to import these Agents.')
28
+    click_on 'Finish Import'
29
+    expect(page).to have_text('Import successful!')
30
+  end
31
+
32
+  it 'asks to accept conflicts when the scenario was modified' do
33
+    DefaultScenarioImporter.seed(user)
34
+    agent = user.agents.where(name: 'Rain Notifier').first
35
+    agent.options['expected_receive_period_in_days'] = 9001
36
+    agent.save!
37
+    visit new_scenario_imports_path
38
+    attach_file('Option 2: Upload a Scenario JSON File', File.join(Rails.root, 'data/default_scenario.json'))
39
+    click_on 'Start Import'
40
+    expect(page).to have_text('This Scenario already exists in your system.')
41
+    expect(page).to have_text('9001')
42
+    check('I confirm that I want to import these Agents.')
43
+    click_on 'Finish Import'
44
+    expect(page).to have_text('Import successful!')
45
+  end
46
+end